﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClassSchoolReport.aspx.cs" Inherits="School_Report_ClassSchoolReport" %>

<%@ Register Src="../../Custom/ucExamClass.ascx" TagName="ucExamClass" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title> 班级成绩明细查询</title>
    
<%--<style type="text/css">
th {cursor: hand;}
</style> --%>
    <link href="../../Common/css/main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../../Common/js/TableForExport.js"></script>
</head>
<script language="javascript">
    var currentsubj =0;
    var first =true;
    var currentdesc=true;
    var doing = false;
    function OnView()
    {
        if(currClassId !=null && currClassId!=0)
        {
            first=true;
            document.getElementById("Textcid").value = currClassId;
            document.getElementById("btnBind").click();
        }
        
    }
    var currObj = null;
    function SetHightLight(obj)
    {
        if(obj!=null)
        {
            if(currObj!=null)
            {
                currObj.style.backgroundColor = "#ffffff";
            }
            obj.style.backgroundColor = "#fffccf";
            currObj = obj;
        }
    }
    function onClassChange()
    {
         OnView();
    }
    

    function sort(index)
    {
        if(!doing)
        {
            doing = true;
            var table = document.getElementById('settingTable');
            if(first && table!=null)
            {
                currentdesc =true;
                currentsubj = table.rows[0].cells.length-1;
                first = false;
            }
            if(index==currentsubj)
            {
                currentdesc = !currentdesc;
                var objs = document.getElementById("img"+index).getElementsByTagName('img');
                  if(objs != null && objs.length > 0)
                  {
                    var obj = objs[0];
                    if(currentdesc)
                    {
                        obj.src = "../../Common/images/1.gif";
                    }
                    else
                    {
                        obj.src = "../../Common/images/2.gif";
                    }
                  }
            }
            else
            {
                var str = document.getElementById("img"+currentsubj).innerHTML;
                document.getElementById("img"+index).innerHTML=str;
                document.getElementById("img"+currentsubj).innerHTML="";
                currentsubj = index;
            }
            
            var tempindex = new Array();
            if(table!=null)
            {
                for(var q =1 ; q < table.rows.length-1;q++)
                {
                    tempindex[q-1] =parseFloat(table.rows[q].cells[currentsubj].innerText == "" ? 0: table.rows[q].cells[currentsubj].innerText);
                   
                }

                    for(var i = 0; i < tempindex.length;i++)
                    {
                        var tti = i;
                        //正序
                        if(!currentdesc)
                        {
                            
                            tti = getmin(tempindex,i);
                        }
                        else
                        {
                            tti = getmax(tempindex,i);
                        }
                        ttti = tempindex[tti];
                        tttii = tempindex[i];
                        for(var j=i;j<=tti;j++)
                        {
                            if(j!=i)
                            {
                                ttti = tttii;
                                tttii = tempindex[j];
                                tempindex[j] = ttti;
                                
                            }
                            else
                            {
                                tttii = tempindex[j];
                                tempindex[j] = ttti;
                            }
                        }
                        table.moveRow(tti+1,i+1 );
                    }
            }
            doing = false;
        }
    }

    function Compare(x, y) { 
    return x == y ? 0 : (x > y ? 1 : -1); 
    } 

    function getmax(tarray,ain)
    {
        maxMan = ain;
        for(var i = ain+1; i < tarray.length;i++)
        {
            if(tarray[maxMan]<=tarray[i])
            {
                maxMan=i;
            }
        }
        return maxMan;
    }
    function getmin(tarray,din)
    {
        var minain =din;
        for(var i = din+1; i < tarray.length;i++)
        {
            if(tarray[minain]>=tarray[i])
            {
                minain=i;
            }
        }
        return minain;
    }
    function getExcel()
    {
        var cells = GetTableInfo(document.getElementById("settingTable"));
        if(cells!=null)
        {
            PageMethods.GetExcel(cells,function(result){
            document.getElementById('downloadf').src = "";
            document.getElementById('downloadf').src = "../../../PostFileBytes.aspx";
//            window.location.href = "../../../PostFileBytes.aspx";
            },function(err){alert(err._message);});
        }
        
    }
</script>
<body style="overflow-y:none;overflow-x:none;height:98%;width:98%;">
<div>
    <form id="form1" runat="server">
            <div class="pageBody">
            <div class="mainWarp" style="padding-top:5px;padding-left:5px;" >
                <table >
                <tr>
                <td  style="padding-left:4px;">
                    班级：<uc1:ucExamClass ID="UcExamClass1" runat="server" />
            <input id="Button1" type="button" value="查询" class="commonBut" style="display:none;"   onclick="OnView()"/>
                    <input id="Button2" type="button" value="导出Excel" style="display:none;" onclick="getExcel()" />
                </td>
                <td style="padding-left:10px;">
                    <asp:UpdateProgress ID="UpdateProgress1"  runat="server" AssociatedUpdatePanelID="UpdatePanel1"><progresstemplate><img src="../../Common/images/ajaxloading.gif" /></progresstemplate></asp:UpdateProgress>
                </td>
                </tr>
                </table><div>
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                    </asp:ScriptManager>
                </div>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Repeater ID="Repeater1" runat="server">
                            <HeaderTemplate>
                            <div>
                                <table id="settingTable" border="0" cellpadding="0" cellspacing="1" class="useList1">
                                        <%= GetHeader()%>
                            </HeaderTemplate>
                            <ItemTemplate>
                                
                                    <%# GetStudent((int)Eval("RID"), Eval("StudentCode").ToString(), Eval("StudentName").ToString())%>
                                
                            </ItemTemplate>
                            <FooterTemplate>
                                <tr style="background-color:White;"  onclick="SetHightLight(this);">                               
                                    <td colspan="2" width='160px' style="text-align:left; font-weight:normal;padding-left:5px;font-weight:bold;"> 
                                         班级均分：
                                    </td>
                                    <%# GetFooter()%>
                                </tr>
                                </table></div>
                            </FooterTemplate>
                        </asp:Repeater>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
                <div style="display: none;">
                  <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
                    <asp:TextBox ID="Textiseexam" runat="server"></asp:TextBox>
                    <asp:TextBox ID="Textid" runat="server"></asp:TextBox>
                    <asp:TextBox ID="Textct" runat="server"></asp:TextBox>
                    <asp:TextBox ID="Textcid" runat="server"></asp:TextBox>
                    <asp:TextBox ID="Textg" runat="server"></asp:TextBox>
                </div>

            </div>
        </div>
        
    </form>
    </div>
    <div id="upInputPop" class="layoutWarp" style="display: none">
        <iframe src="" name="downloadf" id="downloadf" style="height: 80%;width: 95%;overflow-y:auto;overflow-x:none;" frameborder="0"   ></iframe>
    </div>
</body>
</html>
<script language="javascript">
    
    setClassOnChangeFun(onClassChange);
    document.getElementById("Textcid").value = currClassId;
    OnView();
</script>